import React from 'react';
import { IntlProvider } from 'react-intl';
import { ConfigProvider } from '@alifd/next';
// import en from 'react-intl/locale-data/en';
// import zh from 'react-intl/locale-data/zh';
import enUS from '@alifd/next/lib/locale/en-us';
import zhCN from '@alifd/next/lib/locale/zh-cn';
import localeEnUS from '@/locales/en-US';
import localeZhCN from '@/locales/zh-CN';

const localeInfo = {
  'zh-CN': {
    nextLocale: zhCN,
    appLocale: 'zh',
    appMessages: localeZhCN,
  },
  'en-US': {
    nextLocale: enUS,
    appLocale: 'en',
    appMessages: localeEnUS,
  },
};
const LocaleProvider = (props) => {
  const { locale, children } = props;
  const myLocale = localeInfo[locale] ? localeInfo[locale] : localeInfo['en-US'];
  return (
    <IntlProvider locale={myLocale.appLocale} messages={myLocale.appMessages}>
      <ConfigProvider locale={myLocale.nextLocale}>{React.Children.only(children)}</ConfigProvider>
    </IntlProvider>
  );
};

export default LocaleProvider;
